home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / BF_SDK11.ZIP / BLOWFISH.PAS < prev    next >
Pascal/Delphi Source File  |  1996-06-10  |  3KB  |  93 lines

  1.  
  2. {
  3.         BLOWFISH.PAS
  4.         This Unit implements the Blowfish Algorithm as it is defined by
  5.         Bruce Schneier in DDJ 10/95 and "Applied Cryptography, 2nd Edition"
  6.  
  7.         (c)1996 AtmuteSoft
  8.         programmer  : Markus Hahn
  9. }
  10.  
  11. unit Blowfish;
  12.  
  13. interface
  14.  
  15. {**************************************************************************}
  16.  
  17. { The following part was originally declared in a special
  18.   unit called GENERAL.PAS, so it could be used throughout
  19.   the whole application. It isn't necessary, but you might
  20.   want to regenerate GENERAL.PAS }
  21.  
  22. type
  23.  
  24. { own basic data types,
  25.   to avoid system dependencies }
  26.  
  27.   ULONG = Longint;     { unsigned 32bit }
  28.   UINT  = Word;        { unsigned 16bit }
  29.   UCHAR = Byte;        { unsigned 8bit }
  30.   BOOL  = Word;        { 16bit boolean }
  31.  
  32.  
  33. { redef. of special true/false for better portability }
  34. const
  35.  
  36.   MAXDATA = 65535;
  37.  
  38.  
  39. { some large-buffer declarations }
  40. type
  41. P_UCHAR_Buffer = ^T_UCHAR_Buffer;
  42. T_UCHAR_Buffer = array[0..MAXDATA-1] of UCHAR;
  43. P_UINT_Buffer = ^T_UINT_Buffer;
  44. T_UINT_Buffer = array[0..(MAXDATA div 2)-1] of UINT;
  45. P_ULONG_Buffer = ^T_ULONG_Buffer;
  46. T_ULONG_Buffer = array[0..(MAXDATA div 4)-1] of ULONG;
  47.  
  48.  
  49.  
  50.  
  51. {**************************************************************************}
  52.  
  53.  
  54.  
  55. { The exported functions }
  56.  
  57. procedure Blowfish_Init(pKey : P_UCHAR_Buffer; unKeySize : UINT);
  58. procedure Blowfish_ECBEncrypt(pBuffer : P_ULONG_Buffer; unCount : UINT);
  59. procedure Blowfish_ECBDecrypt(pBuffer : P_ULONG_Buffer; unCount : UINT);
  60. procedure Blowfish_CBCEncrypt(pBuffer : P_ULONG_Buffer; unCount : UINT;
  61.                               var ulCBCLeft, ulCBCRight : ULONG);
  62. procedure Blowfish_CBCDecrypt(pBuffer : P_ULONG_Buffer; unCount : UINT;
  63.                               var ulCBCLeft, ulCBCRight : ULONG);
  64. procedure Blowfish_Done;
  65. procedure Blowfish_SetBoxes(pBuffer : P_ULONG_Buffer);
  66. procedure Blowfish_GetBoxes(pBuffer : P_ULONG_Buffer);
  67. function  Blowfish_SetRounds(Rounds : UINT) : UINT;
  68. function  Blowfish_GetBoxPointer : Pointer;
  69. function  Blowfish_WeakKey : BOOL;
  70.  
  71. implementation
  72.  
  73. {$L bfeng386.obj}
  74.  
  75.  
  76. procedure Blowfish_Init(pKey : P_UCHAR_Buffer; unKeySize : UINT); external;
  77. procedure Blowfish_ECBEncrypt(pBuffer : P_ULONG_Buffer; unCount : UINT); external;
  78. procedure Blowfish_ECBDecrypt(pBuffer : P_ULONG_Buffer; unCount : UINT); external;
  79. procedure Blowfish_CBCEncrypt(pBuffer : P_ULONG_Buffer; unCount : UINT;
  80.                               var ulCBCLeft, ulCBCRight : ULONG); external;
  81. procedure Blowfish_CBCDecrypt(pBuffer : P_ULONG_Buffer; unCount : UINT;
  82.                               var ulCBCLeft, ulCBCRight : ULONG); external;
  83. procedure Blowfish_Done; external;
  84. procedure Blowfish_SetBoxes(pBuffer : P_ULONG_Buffer); external;
  85. procedure Blowfish_GetBoxes(pBuffer : P_ULONG_Buffer); external;
  86. function  Blowfish_SetRounds(Rounds : UINT): UINT; external;
  87. function  Blowfish_GetBoxPointer : Pointer; external;
  88. function  Blowfish_WeakKey : BOOL; external;
  89.  
  90. { No Init }
  91. begin
  92. end.
  93.